package km.TestPattern;

import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.DrawFilter;
import android.graphics.Paint;
import android.graphics.PaintFlagsDrawFilter;
import android.graphics.Shader;
import android.os.Bundle;
import android.view.View;

public class TestPattern extends Activity {
    TestPattern mContext;
	private Resources res;
	private Bitmap bm;

	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//    	res = getApplicationContext().getResources();
    	bm = BitmapFactory.decodeResource(getResources(), R.drawable.thumb_bg);

        setContentView(new SampleView(this));
        mContext = this;
    }
    
    private void makeBitmap1() {
//        Bitmap bm = Bitmap.createBitmap(40, 40, Bitmap.Config.RGB_565);
//    	res = getApplicationContext().getResources();
//    	bm = BitmapFactory.decodeResource(res, R.drawable.thumb_bg);
//        Canvas c = new Canvas(bm);
//        c.drawColor(Color.RED);
//        Paint p = new Paint();
//        p.setColor(Color.BLUE);
//        c.drawRect(5, 5, 35, 35, p);
//        return bm;
    }
    
    private  class SampleView extends View {
        private final Shader mShader1;
        private final Paint mPaint;
        private final DrawFilter mFastDF;
        private DrawFilter mDF;

        public SampleView(Context context) {
            super(context);
            setFocusable(true);
            setFocusableInTouchMode(true);

            mFastDF = new PaintFlagsDrawFilter(Paint.FILTER_BITMAP_FLAG |
                                               Paint.DITHER_FLAG,
                                               0);
    
            mShader1 = new BitmapShader(bm, Shader.TileMode.REPEAT,
                                        Shader.TileMode.REPEAT);
            mPaint = new Paint(Paint.FILTER_BITMAP_FLAG);
        }
        
        @Override protected void onDraw(Canvas canvas) {
            canvas.setDrawFilter(mDF);

            mPaint.setShader(mShader1);
            canvas.drawPaint(mPaint);
        }
    }
}